package com.example.wechatbot.controller;

import com.example.wechatbot.service.MessageService;
import com.github.jaemon.dinger.core.entity.DingerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/text")
    public DingerResponse sendText(@RequestBody Map<String, String> request) {
        String content = request.get("content");
        return messageService.sendTextMessage(content);
    }

    @PostMapping("/text/at")
    public DingerResponse sendTextWithAt(@RequestBody Map<String, Object> request) {
        String content = (String) request.get("content");
        @SuppressWarnings("unchecked")
        List<String> phones = (List<String>) request.get("phones");
        return messageService.sendTextMessageWithAt(content, phones);
    }

    @PostMapping("/text/at-all")
    public DingerResponse sendTextAtAll(@RequestBody Map<String, String> request) {
        String content = request.get("content");
        return messageService.sendTextMessageAtAll(content);
    }

    @PostMapping("/markdown")
    public DingerResponse sendMarkdown(@RequestBody Map<String, String> request) {
        String content = request.get("content");
        String title = request.get("title");
        return messageService.sendMarkdownMessage(content, title);
    }
}
